//
//  SPStorePlanEdit.swift
//  Example
//
//  Created by admin on 2020/9/2.
//  Copyright © 2020 admin. All rights reserved.
//

import SwiftUI
import RealmSwift

struct SPStorePlanEdit: View {
    
    @Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>
    
    @State var id = UUID().uuidString
    @State var name:String = ""
    @State var code:String = ""

    
    func insterOrupdata()  {
        let storeData = StoreData()
        storeData.id = id
        storeData.name = name
        storeData.code = code
        storeData.ug_add()
    }

    var body: some View {
        
        
        VStack {
            
            InputView(title: "代码：", plstr: "请输入代码", value: $code)
            InputView(title: "名称:", plstr: "请输入名称", value: $name)
          
            
            Button(action: {
                self.insterOrupdata()
                self.presentationMode.wrappedValue.dismiss()
            }) {
                
                Text("保存")
                    .foregroundColor(Color.white)
            }
            .frame(width: 320.0, height:44)
            .background(Color.red)
            .cornerRadius(8)
            .padding(8)

            Spacer()
        }
        .padding()
        .background(Color.init(red: 0.9, green: 0.9, blue: 0.9))
        .navigationBarTitle(Text("新增"))
        
    }
    
    
}

struct SPStorePlanEdit_Previews: PreviewProvider {
    static var previews: some View {
        
        return SPStorePlanEdit()
    }
}


